package com.endurance.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.core.util.JsonUtils;

import java.util.HashMap;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;

/**
 * @Author: sunlin
 * @Date: 2024-05-11 9:14
 * @Version: 1.0
 * @Description: JVM一级缓存
 */
@Slf4j
public class JVMCacheUtils {

    public static HashMap<String, String> cacheMap = new HashMap<>();


    public static void putEntity(String key, Object object) {
        cacheMap.put(key, JSON.toJSONString(object));
    }


    public static <T> T getEntity(String key, Class<T> t) {
        String json = cacheMap.get(key);

        log.info("json对象：", json);
        return JSON.parseObject(json, t);
    }

}
